package com.haoyun.common.exception;

import com.haoyun.common.exception.config.GlobalErrorProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by twg on 2018/2/25.
 * 全局异常配置类型
 */
@Configuration
@EnableConfigurationProperties(value = {GlobalErrorProperties.class})
public class GlobalErrorConfigurationWrapper {
    @Autowired
    private ErrorAttributes errorAttributes;
    @Bean
    @ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
    public GlobalErrorController globalErrorController() {
        return new GlobalErrorController(errorAttributes);
    }
}
